package com.hzjq.encrypt.pop

import android.content.Context
import com.hzjq.encrypt.R
import com.hzjq.encrypt.bean.Zbqy
import com.hzjq.encrypt.util.KeyBoradX
import com.lxj.xpopup.XPopup
import com.lxj.xpopup.core.CenterPopupView
import kotlinx.android.synthetic.main.pop_jbqy_layout.view.*

class ZbqyEditorPop : CenterPopupView {

    private lateinit var zbqy: Zbqy
    private lateinit var c: OnZbqyEditorCallback

    constructor(context: Context) : super(context)

    override fun getImplLayoutId(): Int {
       return R.layout.pop_jbqy_layout
    }

    override fun onCreate() {
        jbqyPopJdEt.setText(zbqy.zbqyjd)
        jbqyPopWdEt.setText(zbqy.zbqywd)
        jbqyPopBjmEt.setText(zbqy.zbqybj)
        jbqyPopQssjEt.setText(zbqy.zbqssj)
        jbqyPopJzsjEt.setText(zbqy.zbjzsj)

        jbqyPopCancelText.setOnClickListener {
            hideKeyBord()
            dismiss()
        }

        jbqyPopSureText.setOnClickListener {
            hideKeyBord()
            dismiss()
            zbqy.zbqyjd = jbqyPopJdEt.text.toString()
            zbqy.zbqywd = jbqyPopWdEt.text.toString()
            zbqy.zbqybj = jbqyPopBjmEt.text.toString()
            zbqy.zbqssj = jbqyPopQssjEt.text.toString()
            zbqy.zbjzsj = jbqyPopJzsjEt.text.toString()
            c.onZbqyEditor(zbqy)
        }
    }


    private fun hideKeyBord(){
        KeyBoradX.hideKeyBoard(jbqyPopJdEt)
        KeyBoradX.hideKeyBoard(jbqyPopWdEt)
        KeyBoradX.hideKeyBoard(jbqyPopBjmEt)
        KeyBoradX.hideKeyBoard(jbqyPopQssjEt)
        KeyBoradX.hideKeyBoard(jbqyPopJzsjEt)
    }

    interface OnZbqyEditorCallback {
        fun onZbqyEditor(zbqy: Zbqy)
    }

    companion object {
        fun show(context: Context, c: OnZbqyEditorCallback, data: Zbqy?){
            val pop = ZbqyEditorPop(context)
            if(data != null) {
                pop.zbqy = data
            } else {
                pop.zbqy = Zbqy()
            }
            pop.c = c
            XPopup.Builder(context)
                .asCustom(pop)
                .show()
        }
    }
}